<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<head>
<title>_库存锁定</title>
<script type="text/javascript">
var stocks = [];
$(function() {
		$("#queryForm").validate();
		bindCheckBox("myCheckedAll","myChecked"); 
		$("input[name=myChecked]").on("ifChecked", function(event){
			stocks.push(event.target.value);
		});
		$("input[name=myChecked]").on("ifUnchecked", function(event){
			stocks=$.grep(stocks, function(n,i){
				  return n != event.target.value;
				});
		});
});
	
function query(){
	$("#queryForm").submit();
}
//锁定当前记录
function lock(){
	if(stocks && stocks.length > 0){
		$.ajax({ 
	       type: "post",
	       contentType: "application/json", 
	       url: "${ctx}/v2_storageLock/lock",    
	       dataType: "json",   
	       data: JSON.stringify(stocks),
	       success : function(data) {
	       		jAlert("操作成功");
	       		query();
			},
		    error : function(data) {
				jAlert("操作失败，请检查该sku是否还有未处理完成的订单");
			}
	   });
	}else{
		jAlert("请选择要锁定的记录");
	}
}
//解锁当前记录
function unLock(){
	if(stocks && stocks.length > 0){
		$.ajax({ 
	       type: "post",
	       contentType: "application/json", 
	       url: "${ctx}/v2_storageLock/unLock",
	       dataType: "json",   
	       data: JSON.stringify(stocks),
	       success : function(data) {
	       		jAlert("操作成功");
	       		query();
			},
		    error : function(data) {
				jAlert("操作失败，请检查该sku是否还有未处理完成的订单");
			}
	   });
	}else{
		jAlert("请选择要解锁的记录");
	}
}

</script>
</head>
<body>
<section class="content">
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				<form class="form-search" id="queryForm" action="${ctx}/v2_storageLock/query" method="post">
					<div class="form-group row">
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
								<span class="input-group-text"> 商家： </span> 
								<select class="form-control required" id="customerCode" name="customerCode" onchange="ajaxAreaGroup(this,'warehouseCode')">
									<option value=""></option>
									<c:forEach items="${customerList}" var="customer" >
										<option value="${customer.customerCode}"
											<c:if test="${param['customerCode'] eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
								<span class="input-group-text"> 仓库： </span> 
								<select class="form-control span3 required" id="warehouseCode" name="warehouseCode">
									<option value=""></option>
									<c:forEach items="${warehouseList}" var="warehouse">
										<option value="${warehouse.groupCode}"
											<c:if test="${param.warehouseCode eq warehouse.groupCode }">selected=selected</c:if>>${warehouse.groupName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
								<span class="input-group-text"> SKU： </span> 
								<input class="form-control span3 required" id="sku" name="sku" value="${param.sku }"/>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
								<button class="btn btn-info" type="button" onclick="query()">查询</button>
								<a class="btn btn-primary" type="button" onclick="lock()">锁定</a>
			   					<a class="btn btn-primary" type="button" onclick="unLock()">解锁</a>
							</div>
						</div>

					</div>
				</form>
				</div>

			</div>
			<!-- /.box-body -->

		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
				<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div></div>
				<div class="box-body">
				<form id="dataForm">
					<table id="orgTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th><input type="checkbox" name="myCheckedAll" id="myCheckedAll"/></th>
								<th>序号</th>
								<th>商家</th>
								<th>仓库</th>
								<th>SKU</th>
								<th>可销售库存</th>
								<th>锁定库存</th>
								<th>库位</th>
								<th>箱编码</th>
							</tr>
						</thead>
						<tbody>
						<c:forEach items="${cusStocks}" var="o" varStatus="i">
						<tr>
			   				<td><input type="checkbox" name="myChecked" id="check${o.id }" value="${o.id }"/></td>
			   				<td>${i.count}</td>
			   				<td id="customerName_${o.id }">${o.customer.customerName}</td>
			   				<td id="warehouseCode_${o.id }">
				   				<c:forEach items="${warehouseList}" var="warehouse">
					   				<c:if test="${warehouse.groupCode eq o.warehouseCode}">
					   					${warehouse.groupName}
					   				</c:if>
								</c:forEach>
			   				</td>
			   				<td id="sku_${o.id }">${o.sku}</td>
			   				<td id="salesNum_${o.id }">${o.salesNum}</td>
			   				<td id="lockedNum_${o.id }">${o.lockedNum}</td>
			   				<td id="stockCode_${o.id }">${o.stockCode }</td>
			   				<td id="boxCode_${o.id }">${o.boxCode }</td>
			   			</tr>
						</c:forEach>
						</tbody>
					</table>
					</form>
				</div>
			</div>
			<!-- /.box -->
		</div>
		<!-- /.col -->
	</div>
</section>	
</body>
</html>